package cn.isjinhao.se.sql.grammar.statement.delete.visitor;

import cn.isjinhao.se.sql.grammar.statement.StatementAstMetaInfoDetectorDelegate;
import cn.isjinhao.se.sql.grammar.statement.delete.SingleDeleteMetaInfo;
import cn.isjinhao.se.sql.grammar.statement.delete.represention.Delete;
import cn.isjinhao.se.sql.lexical.token.Token;

import java.util.Set;

/**
 * @Author ISJINHAO
 * @Date 2021/4/10 9:20
 */
public class SingleDeleteMetaInfoDetector extends DeleteVisitorWithDelegate<Set<Token>> {

    private SingleDeleteMetaInfo singleDeleteMetaInfo;

    public SingleDeleteMetaInfoDetector() {
        super.init(new StatementAstMetaInfoDetectorDelegate(this));
    }

    @Override
    public Set<Token> visitDelete(Delete delete) {
        init(delete);
        Token tableName = delete.getTableName();
        singleDeleteMetaInfo.addReferenceTable(tableName);
        Set<Token> accept = delete.getWhereSeg().accept(this);
        singleDeleteMetaInfo.addReferenceColumnSet(accept);
        return null;
    }

    private void init(Delete delete) {
        singleDeleteMetaInfo = new SingleDeleteMetaInfo(delete);
        delete.setSingleDeleteMetaInfo(singleDeleteMetaInfo);
    }


}
